package h0813;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
/**
  * @description 简易内存池
  * @author 不知名帅哥
  * @date 2024/8/13 22:42
  * @version 1.0
*/
class MemoryPool {
    private final int size = 100;
    private final byte[] memory = new byte[size];
    private final List<int[]> allocations = new ArrayList<>();

    public String request(int size) {
        if (size <= 0) {
            return "error";
        }

        for (int i = 0; i <= this.size - size; i++) {
            boolean found = true;
            for (int j = 0; j < size; j++) {
                if (memory[i + j] != 0) {
                    found = false;
                    break;
                }
            }
            if (found) {
                for (int j = 0; j < size; j++) {
                    memory[i + j] = 1;
                }
                allocations.add(new int[]{i, size});
                return String.valueOf(i);
            }
        }
        return "error";
    }

    public String release(int start) {
        for (int i = 0; i < allocations.size(); i++) {
            int[] alloc = allocations.get(i);
            if (alloc[0] == start) {
                for (int j = start; j < start + alloc[1]; j++) {
                    memory[j] = 0;
                }
                allocations.remove(i);
                return null;
            }
        }
        return "error";
    }

    public List<String> executeCommands(List<String> commands) {
        List<String> results = new ArrayList<>();
        for (String command : commands) {
            if (command.startsWith("REQUEST=")) {
                int size = Integer.parseInt(command.split("=")[1]);
                String result = request(size);
                if (!"error".equals(result)) {
                    results.add(result);
                } else {
                    results.add("error");
                }
            } else if (command.startsWith("RELEASE=")) {
                int start = Integer.parseInt(command.split("=")[1]);
                String result = release(start);
                if ("error".equals(result)) {
                    results.add("error");
                }
            }
        }
        return results;
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = Integer.parseInt(scanner.nextLine().trim());
        List<String> commands = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            commands.add(scanner.nextLine().trim());
        }
        scanner.close();

        MemoryPool memoryPool = new MemoryPool();
        List<String> results = memoryPool.executeCommands(commands);
        for (String result : results) {
            System.out.println(result);
        }
    }
}
